package com.ruoyi.dm.component;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import com.ruoyi.common.constant.CollectFileTypeConstants;
import com.ruoyi.common.utils.biz.BizModule;
import com.ruoyi.common.utils.biz.PathUtil;
import com.ruoyi.dm.domain.po.ReanalysisCollectRecordPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 空间 再分析数据
 */
@Component
@Slf4j
public class ReAnalysisStrategy implements DataStrategy<ReanalysisCollectRecordPO> {

    @Override
    public ReanalysisCollectRecordPO makeupPo(ReanalysisCollectRecordPO po) {

        String fileName = po.getFileName();
        //ukmo_pressure_levels_202004.grib
        String[] split = fileName.split("_|\\.");
        //po.setDataType(split[1]);
        po.setFileDate(Integer.valueOf(split[3]));
        return po;
    }

    @Override
    public String pythonCmd(String satellite, String dataType, String filePath,String method, Integer year) {
        String fileType = CollectFileTypeConstants.TYPE_ANALYSIS;
        String outPath = PathUtil.outputModuleDir(BizModule.COLLECT) + PathUtil.moduleDirs().getCollect().get("result") ;
        FileUtil.mkdir(outPath);
        String logPath = PathUtil.tmpModuleDir(BizModule.COLLECT) + PathUtil.moduleDirs().getCollect().get("result");
        FileUtil.mkdir(logPath);
        String script = PathUtil.codeModuleDir(BizModule.COLLECT) + PathUtil.moduleDirs().getCollect().get("ukmoScript");
        String[] cmdLines = new String[12];

        cmdLines[0] = "python";
        cmdLines[1] = script;
        cmdLines[2] = "--filepath";//原始文件
        cmdLines[3] = filePath;
        cmdLines[4] = "--outfile";//产品路径
        cmdLines[5] = outPath;
        cmdLines[6] = "--outlog";//日志路径
        cmdLines[7] = logPath;
        cmdLines[8] = "--inter_type";//评估结果路径
        cmdLines[9] = method;
        cmdLines[10] = "--resolution";//网格间隔 [2.5, 2.5, 2.5]
        cmdLines[11] = dataType;
        String commond = ArrayUtil.join(cmdLines, " ");
        log.info("拼接脚本:{}", commond);
        return commond;
    }
}
